package com.example.doer.reading;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;

import com.ab.fragment.AbFragment;
import com.ab.view.pullview.AbPullToRefreshView;

import java.util.ArrayList;
import java.util.List;

import static android.os.SystemClock.sleep;
import static com.google.android.gms.internal.zzagz.runOnUiThread;

/**
 * Created by 严旭江 on 2017/7/11.
 */

//话题---为一个碎片
public class FragmentTwo extends AbFragment {

    //上拉进行刷新
    private AbPullToRefreshView abPullToRefreshView_topic=null;

    public FragmentTwo(){

    }
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState){
        //使用fragment_topic作为该fragment的主界面
        //fragment_topic仅含一个空的listView
        View view=inflater.inflate(R.layout.fragment_topic, container, false);

        //获取fragment_topic中的ListView的引用
        ListView listView = (ListView)view.findViewById(R.id.topic_list);
        listView.setPadding(2,2,2,2);
        //创建Topic的对象集合
        List<Topic> topicList = new ArrayList<Topic>();
        //通过获取数据库中的内容进行传递
        /**
         * 待实现
         */
        //下举例使用
        //topic userID,userName,resID,catagory,title(name),content   6args
        Topic topic = new Topic(1,"下辈子再续",2,"玄幻小说","为什么大主宰经常被人喷？","土豆RP不行，经常偷懒，" + "而且找借口托更，让读者十分生气");
        topic.getTopicReply().add(new TopicReply(topic.getTopicID(),"回复者1",1,"content1"));
        topicList.add(topic);

        Topic topic1 = new Topic(2,"zhang",5,"都市","论极品家丁","YY文巅峰");
        topic1.getTopicReply().add(new TopicReply(topic1.getTopicID(),"回复者2",2,"content2"));
        topic1.getTopicReply().add(new TopicReply(topic1.getTopicID(),"回复者1",1,"content1"));
        topicList.add(topic1);

        Topic topic2 = new Topic(3,"夜凝夕夕",5,"都市","论极品家丁","YY文巅峰是固伤不是固伤随后高搜我后手v公司好感动过hi欧的hi瓯海工商 hi瓯海公司哦哈够是够似乎更我org后悔覅公司回购我好搜ID红狗我很生动我给搜 荒古我哦化工等红灯hi欧皇佛我hi偶数佛is后手的和供水公司佛我和文化馆搜宏观iOS人和狗很生动 和voshgoshgoishiobhoishghgoihwgoh 荒古iOS荒古iOS鸿沟是共商国是 还搞死欧皇个iOS鸿沟是给哦个后手共和国是 手感我hi噢收购IE红狗is何工is何工is鸿沟是广东省共is鸿沟是够的时候is荷藕is过后是够我hi偶尔回购和回顾额工单号古代诗歌胸怀个 ");
        //topic2.getTopicReply().add(new TopicReply(topic2.getTopicID(),"回复者3",3,"content3"));
        topicList.add(topic2);

//        topicList.add(new Topic(1,"下辈子再续",2,"玄幻小说","为什么大主宰经常被人喷？","土豆RP不行，经常偷懒，" + "而且找借口托更，让读者十分生气"));
//        topicList.add(new Topic(2,"zhang",5,"都市","论极品家丁","YY文巅峰"));
//        topicList.add(new Topic(2,"夜凝夕夕",5,"都市","论极品家丁","YY文巅峰是固伤不是固伤随后高搜我后手v公司好感动过hi欧的hi瓯海工商 hi瓯海公司哦哈够是够似乎更我org后悔覅公司回购我好搜ID红狗我很生动我给搜 荒古我哦化工等红灯hi欧皇佛我hi偶数佛is后手的和供水公司佛我和文化馆搜宏观iOS人和狗很生动 和voshgoshgoishiobhoishghgoihwgoh 荒古iOS荒古iOS鸿沟是共商国是 还搞死欧皇个iOS鸿沟是给哦个后手共和国是 手感我hi噢收购IE红狗is何工is何工is鸿沟是广东省共is鸿沟是够的时候is荷藕is过后是够我hi偶尔回购和回顾额工单号古代诗歌胸怀个 "));
//        topicList.add(new Topic(3,"夜凝夕夕",5,"都市","论极品家丁","YY文巅峰是固伤不是固伤随后高搜我后手v公司好感动过hi欧的hi瓯海工商 hi瓯海公司哦哈够是够似乎更我org后悔覅公司回购我好搜ID红狗我很生动我给搜 荒古我哦化工等红灯hi欧皇佛我hi偶数佛is后手的和供水公司佛我和文化馆搜宏观iOS人和狗很生动 和voshgoshgoishiobhoishghgoihwgoh 荒古iOS荒古iOS鸿沟是共商国是 还搞死欧皇个iOS鸿沟是给哦个后手共和国是 手感我hi噢收购IE红狗is何工is何工is鸿沟是广东省共is鸿沟是够的时候is荷藕is过后是够我hi偶尔回购和回顾额工单号古代诗歌胸怀个 "));
//        topicList.add(new Topic(3,"夜凝夕夕",5,"都市","论极品家丁","YY文巅峰是固伤不是固伤随后高搜我后手v公司好感动过hi欧的hi瓯海工商 hi瓯海公司哦哈够是够似乎更我org后悔覅公司回购我好搜ID红狗我很生动我给搜 荒古我哦化工等红灯hi欧皇佛我hi偶数佛is后手的和供水公司佛我和文化馆搜宏观iOS人和狗很生动 和voshgoshgoishiobhoishghgoihwgoh 荒古iOS荒古iOS鸿沟是共商国是 还搞死欧皇个iOS鸿沟是给哦个后手共和国是 手感我hi噢收购IE红狗is何工is何工is鸿沟是广东省共is鸿沟是够的时候is荷藕is过后是够我hi偶尔回购和回顾额工单号古代诗歌胸怀个 "));
//        topicList.add(new Topic(3,"夜凝夕夕",5,"都市","论极品家丁","YY文巅峰是固伤不是固伤随后高搜我后手v公司好感动过hi欧的hi瓯海工商 hi瓯海公司哦哈够是够似乎更我org后悔覅公司回购我好搜ID红狗我很生动我给搜 荒古我哦化工等红灯hi欧皇佛我hi偶数佛is后手的和供水公司佛我和文化馆搜宏观iOS人和狗很生动 和voshgoshgoishiobhoishghgoihwgoh 荒古iOS荒古iOS鸿沟是共商国是 还搞死欧皇个iOS鸿沟是给哦个后手共和国是 手感我hi噢收购IE红狗is何工is何工is鸿沟是广东省共is鸿沟是够的时候is荷藕is过后是够我hi偶尔回购和回顾额工单号古代诗歌胸怀个 "));
//        topicList.add(new Topic(3,"夜凝夕夕",5,"都市","论极品家丁","YY文巅峰是固伤不是固伤随后高搜我后手v公司好感动过hi欧的hi瓯海工商 hi瓯海公司哦哈够是够似乎更我org后悔覅公司回购我好搜ID红狗我很生动我给搜 荒古我哦化工等红灯hi欧皇佛我hi偶数佛is后手的和供水公司佛我和文化馆搜宏观iOS人和狗很生动 和voshgoshgoishiobhoishghgoihwgoh 荒古iOS荒古iOS鸿沟是共商国是 还搞死欧皇个iOS鸿沟是给哦个后手共和国是 手感我hi噢收购IE红狗is何工is何工is鸿沟是广东省共is鸿沟是够的时候is荷藕is过后是够我hi偶尔回购和回顾额工单号古代诗歌胸怀个 "));
//        topicList.add(new Topic(3,"夜凝夕夕",5,"都市","论极品家丁","YY文巅峰是固伤不是固伤随后高搜我后手v公司好感动过hi欧的hi瓯海工商 hi瓯海公司哦哈够是够似乎更我org后悔覅公司回购我好搜ID红狗我很生动我给搜 荒古我哦化工等红灯hi欧皇佛我hi偶数佛is后手的和供水公司佛我和文化馆搜宏观iOS人和狗很生动 和voshgoshgoishiobhoishghgoihwgoh 荒古iOS荒古iOS鸿沟是共商国是 还搞死欧皇个iOS鸿沟是给哦个后手共和国是 手感我hi噢收购IE红狗is何工is何工is鸿沟是广东省共is鸿沟是够的时候is荷藕is过后是够我hi偶尔回购和回顾额工单号古代诗歌胸怀个 "));

        //为listView添加自定义适配器
        //使用topic_listview自定义的一个话题布局 将每个话题展示出来
        //传递getActivity便于页面跳转
        MyTopicAdapter myTopicAdapter = new MyTopicAdapter(getActivity(),topicList,R.layout.topic_listview);
        //更改adapter构造
        //MyTopicAdapter myTopicAdapter = new MyTopicAdapter(getActivity(),topicList);
        listView.setAdapter(myTopicAdapter);

        //下滑刷新
        abPullToRefreshView_topic=(AbPullToRefreshView)view.findViewById(R.id.PullRefreshView_topic);
        abPullToRefreshView_topic.setOnHeaderRefreshListener(new AbPullToRefreshView.OnHeaderRefreshListener() {
            @Override
            public void onHeaderRefresh(final AbPullToRefreshView abPullToRefreshView_topic) {
                refresh();
            }
        });

        abPullToRefreshView_topic.setOnFooterLoadListener(new AbPullToRefreshView.OnFooterLoadListener() {
            @Override
            public void onFooterLoad(AbPullToRefreshView abPullToRefreshView) {

            }
        });
        return view;
    }//end methos onCreateView

    public void refresh(){
        new Thread(new Runnable() {
            @Override
            public void run() {
                sleep(2000);
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        abPullToRefreshView_topic.onHeaderRefreshFinish();
                    }
                });
            }
        }).start();
    }
}//end class
